﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Minecraft.Config.Csv.CsvCom;
using Minecraft.Model;
using Minecraft.Model.Goods;

namespace Minecraft.Config.Csv.CsvCls
{
	public partial class Mod_Items
	{
		/// <summary>
		/// 背包物品格子放置数量上限
		/// </summary>
		public int Max_num_Convert
		{
			get
			{
				int.TryParse(Max_num, out int maxNum);
				return maxNum;
			}
		}
		public EnumGoodsType enumGoodsType_Convert
		{
			get
			{
				//由字符串转化为枚举值
				var goodsTypeList = EnumGoodsType.All.GetEnumDesxriptionDict().Select(m => (EnumGoodsType)m.Key).ToList();
				goodsTypeList.Remove(EnumGoodsType.All);
				var typeInfoList = goodsTypeList.Select(m => new GoodsTypeInfo
				{
					enumGoodsType = m,
					enumGoodsTypeStr = m.ToString()
				}).ToList();
				var strs = Type.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
				if (strs.Length < 2)
				{
					throw new Exception("item type 配置有问题");
				}
				var typeStr = strs[1];
				var typeInfo = typeInfoList.FirstOrDefault(m => m.enumGoodsTypeStr == typeStr);
				if (typeInfo == null)
				{
					throw new Exception($"item type 配置表中未找到该类型【{typeStr}】");
				}
				return typeInfo.enumGoodsType;
			}
		}
		
		/// <summary>
		/// 物品的属性以及对应的属性值（依赖属性表）
		/// </summary>
		public ModAttributeInfo modAttributeInfo_Convert
		{
			get
			{
				var attrs = Attribute.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
				if (attrs.Length == 2)
				{
					return new ModAttributeInfo
					{
						Id = int.Parse(attrs[0]),
						AttributeName = CsvConfig.GetMod_AttributeInfoById(attrs[0]).Attribute_name,
						Value = int.Parse(attrs[1]),
					};
				}
				else
				{
					return new ModAttributeInfo
					{
						Id = -1,
						AttributeName = "未知",
						Value = -1
					};
				}
			}
		}
	}
}
